package com.zxlspace.thread;

import com.zxlspace.proxy.Web12306;

public class WebBuyTicket {
    public static void main(String[] args) {
        Buyer buyer = new BuyerImpl();
        BuyerCompany buyerCompany = new BuyerCompany(buyer);
        buyerCompany.buy();

        Web12306 web12306 = new Web12306();
        Thread t1 = new Thread(web12306, "黄牛1号");
        Thread t2 = new Thread(web12306, "黄牛2号");
        Thread t3 = new Thread(web12306, "黄牛3号");

        t1.start();
        t2.start();
        t3.start();
    }
}

interface Buyer {
    void buy();
}

class BuyerImpl implements Buyer {

    @Override
    public void buy() {
        System.out.println("我来买票了");
    }
}

class BuyerCompany implements Buyer {

    private Buyer buyer;

    public BuyerCompany(Buyer buyer) {
        this.buyer = buyer;
    }

    public void before() {
        System.out.println("我是代理公司");
    }

    @Override
    public void buy() {
        before();
        buyer.buy();
    }
}

class Web12036 implements Runnable {

    private int num = 500;
    private boolean flag = true;

    @Override
    public void run() {
        while (flag) {
            if (num <= 200) {
                this.stop();
            }
            System.out.println("抢到票了----》" + num--);
        }
    }

    public void stop() {
        this.flag = false;
    }
}

